//
//  WebViewViewController.m
//  TodatPlay
//
//  Created by dllo on 16/9/7.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "WebViewViewController.h"
#import "SDAutoLayout.h"
@interface WebViewViewController ()<UIWebViewDelegate>

@end

@implementation WebViewViewController{
    UIWebView *webViewOfVC;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    webViewOfVC = [[UIWebView alloc] initWithFrame:self.view.bounds];
    NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:_webURLString]];
    [self.view addSubview: webViewOfVC];
    [webViewOfVC loadRequest:request];
    webViewOfVC.delegate = self;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    webViewOfVC.scrollView.bounces = NO;
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"left_icon"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ] style:UIBarButtonItemStylePlain target:self action:@selector(clickLeftBarButton:)];
}
#pragma mark - 获取webView的标题
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 0, self.view.bounds.size.width - 150, 44)];
    titleLabel.font = [UIFont systemFontOfSize:15];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.text = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
}
#pragma mark - 左button的点击方法
- (void)clickLeftBarButton:(UIBarButtonItem *)barButton {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
